import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;

public class Exp {
    public static void main(String args[]) {
        File srcFile = new File("Calem.txt");
        File destFile = new File("Modified.txt");
        Scanner cin = new Scanner(System.in);
        System.out.println("What word would you like to remove?");
        System.out.print(">");
        String word = cin.next();
        if (!srcFile.exists()) {
            System.out.println("File does not exist.");
            return;
        }
        try (Scanner in = new Scanner(srcFile);
             PrintWriter out = new PrintWriter(destFile);) {
            while (in.hasNext()) {
                StringBuilder line = new StringBuilder(in.nextLine());
                int current = 0;
                //删除本行中的目标单词
                while (current <= line.length() - 1) {
                    current = line.indexOf(word, current);
                    if (current >= 0) {
                        line.delete(current, current + word.length());
                    }
                    else break;
                }
                out.println(line);
            }
        }
        catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }
        System.out.println("The word has been removed from the passage " +
                "successfully.");
    }
}